package com.sctvcloud.qingchuan.ui.adapter.holder;

import android.content.Context;
import android.view.View;
import android.widget.ImageView;
import android.widget.Toast;

import com.ruihang.generalibrary.ui.widget.CustomFontTextView;
import com.sctvcloud.qingchuan.R;
import com.sctvcloud.qingchuan.beans.PoliticsAccountBean;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * 问政对象
 */
public class PoliticsAccountHolder extends BaseAbsHolder<PoliticsAccountBean> implements View.OnClickListener {

    @BindView(R.id.item_title)
    protected CustomFontTextView title;
    @BindView(R.id.selected_img)
    protected ImageView selectedImg;

    private PoliticsAccountBean temp;
    private OnPoliticsAccountClickListener listener;

    public PoliticsAccountHolder(Context context, View itemView, OnPoliticsAccountClickListener listener) {
        super(context, itemView);
        itemView.setOnClickListener(this);
        this.listener = listener;
    }


    @Override
    protected void initInject() {
        ButterKnife.bind(this, itemView);
    }

    @Override
    public void setData(PoliticsAccountBean t) {
        temp = t;
        title.setText(t.getUserName());

        if (t.isSelected()) {
            selectedImg.setVisibility(View.VISIBLE);
        } else {
            selectedImg.setVisibility(View.INVISIBLE);
        }
    }

    @Override
    public void setItemMode(int mode) {
        super.setItemMode(mode);
//        if (mode == ITEMMODE_LAST) {
//            bottomLine.setVisibility(View.GONE);
//        } else {
////            bottomLine.setVisibility(View.VISIBLE);
//        }
    }

    @Override
    public void onDestory() {
        super.onDestory();
        if (itemView != null) {
            itemView.setOnClickListener(null);
        }
    }

    @Override
    public void onClick(View v) {
        if (temp == null) {
            Toast.makeText(context, "数据错误", Toast.LENGTH_SHORT).show();
            return;
        }
        //TODO 选择问政对象
        if (null != listener) {
            listener.OnAccountClick(temp);
        }
    }

    public interface OnPoliticsAccountClickListener {
        void OnAccountClick(PoliticsAccountBean account);
    }

}
